package com.jvm.outofmemoryerror;

import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.Opcodes;

/**
 * @author: csh
 * @Date: 2021/4/6 14:09
 * @Description:方法区内存溢出
 */
public class Ares extends  ClassLoader {
    public static void main(String[] args) {
        int i = 0;
        Ares ares = new Ares();
        while (true) {
            i++;
            ClassWriter cw = new ClassWriter(0);
            cw.visit(Opcodes.V1_8,Opcodes.ACC_PUBLIC,"Class"+i,null,"java/lang/Object",null);
            byte[] code = cw.toByteArray();
            ares.defineClass("Class"+i,code,0,code.length);
            System.out.println(i);
        }
    }
}
